package com.rjyb.dyxz.unit;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DB {
    private static final String url = "jdbc:mysql://localhost:3306/shopping";
    private static final String uName = "root";
    private static final String pwd = "123456";
    private static Connection conn = null;

    private DB(){}

    public static Connection getConnection(){
        try {
            Class.forName("com.mysql.jdbc.Driver");

        } catch (ClassNotFoundException e) {
            System.out.println("jdbc驱动错误");
        }
        try {
            conn = DriverManager.getConnection(url,uName,pwd);
        } catch (SQLException e) {
            System.out.println("链接数据库失败");
        }
        return conn;
    }

    public static void main(String[] args) {
        System.out.println(getConnection());
    }

}
